<template>
	<view>
		<view class="address-choose-box" v-if="JSON.stringify(address) === '{}'">
			<button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址</button>
		</view>
		<view class="address-info-box" v-else @click="chooseAddress">
			<view class="row">
				<view class="row-left">
					<text>收货人：</text>
					<text>{{address.userName}}</text>
				</view>
				<view class="row-right">
					<view>
						<text>电话：</text>
						<text>{{address.telNumber}}</text>
					</view>
					<uni-icons type="forward" size="16"></uni-icons>
				</view>
			</view>
			<view class="address">
				<text class="addressName">收货地址：</text>
				<text>{{addressInfo}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState, mapMutations, mapGetters } from 'vuex';
	export default {
		name:"my-address",
		data() {
			return {
			};
		},
		computed:{
			...mapState('m_user', ['address']),
			...mapGetters('m_user', ['addressInfo'])
		},
		methods: {
			...mapMutations('m_user', ['updateAddress']),
			async chooseAddress(){
				console.log(this.address)
				const res = await uni.chooseAddress().catch(err => err)
				if(res.errMsg !== "chooseAddress:ok") return
				this.updateAddress(res)
			}
		}
	}
</script>

<style lang="scss">
.address-choose-box{
	height: 90px;
	display: flex;
	align-items: center;
	justify-content: center;
}
.address-info-box{
	display: flex;
	flex-direction: column;
	justify-content: center;
	font-size: 12px;
	height: 90px;
	padding: 0 5px;
	.row{
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10px;
		.row-right{
			display: flex;
			justify-content: space-between;
		}
	}
	.address{
		display: flex;
		.addressName{
			white-space: nowrap;
		}
	}
}
</style>